//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package io.renren.utils;

import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;

import java.util.HashMap;

public class ResponseParam extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;
    public static final String SUCCESS_PARAM_VALUE = "success";
    public static final String MESSAGE_PARAM = "message";
    public static final String DATA_PARAM = "data";
    public static final String CODE_PARAM = "code";
    private boolean isSupportJSONP = true;

    private ResponseParam() {
    }

    public static ResponseParam info(boolean flag) {
        return flag?success():fail();
    }

    public ResponseParam supportJSONP(boolean isSupportJSONP) {
        this.isSupportJSONP = isSupportJSONP;
        return this;
    }

    public static ResponseParam success() {
        return success(true);
    }

    public static ResponseParam fail() {
        return success(false);
    }

    public static ResponseParam success(boolean flag) {
        ResponseParam successParam = new ResponseParam();
        successParam.put("success", Boolean.valueOf(flag));
        return successParam;
    }

    public static ResponseParam updateSuccess() {
        ResponseParam successParam = success();
        successParam.addMessage("更新成功");
        return successParam;
    }

    public static ResponseParam updateFail() {
        ResponseParam failParam = fail();
        failParam.addMessage("更新失败");
        return failParam;
    }

    public static ResponseParam saveSuccess() {
        ResponseParam successParam = success();
        successParam.addMessage("添加成功");
        return successParam;
    }

    public static ResponseParam saveFail() {
        ResponseParam failParam = fail();
        failParam.addMessage("添加失败");
        return failParam;
    }

    public static ResponseParam deleteSuccess() {
        ResponseParam successParam = success();
        successParam.addMessage("删除成功");
        return successParam;
    }

    public static ResponseParam deleteFail() {
        ResponseParam failParam = fail();
        failParam.addMessage("删除失败");
        return failParam;
    }

    public ResponseParam addCode(Object code) {
        this.put("code", code);
        return this;
    }

    public ResponseParam addMessage(Object value) {
        this.put("message", value);
        return this;
    }

    public ResponseParam addData(Object value) {
        this.put("data", value);
        return this;
    }

    public ResponseParam addParam(String key, Object value) {
        this.put(key, value);
        return this;
    }

    public ResponseEntity<ResponseParam> getResponseEntity() {
        return this.getResponseEntity(HttpStatus.OK);
    }

    public ResponseEntity<ResponseParam> getResponseEntity(HttpStatus httpStatus) {
        return this.getResponseEntity(httpStatus, (MediaType)null);
    }

    public ResponseEntity<ResponseParam> getResponseEntity(HttpStatus httpStatus, MediaType contentType) {
        if(httpStatus == null) {
            httpStatus = HttpStatus.OK;
        }

        if(contentType == null) {
            contentType = MediaType.APPLICATION_JSON;
        }

        return ResponseEntity.status(httpStatus).contentType(contentType).body(this);
    }

    public boolean isSupportJSONP() {
        return this.isSupportJSONP;
    }
}
